package com.ruoyi.packag.mapper;

import cn.jy.common.index.Count;
import com.ruoyi.packag.domain.*;
import com.ruoyi.packag.domain.Package;
import cn.jy.common.index.LineChart;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface PackageMapper {
    @Select("select * from express_package")
    List<Package> show(Package p);
    @Select("select * from express_timeline where wai=#{id}")
    List<Timeline> cha1(@Param("id") Integer id);
    @Select("select * from express_vending_machines where id=#{id}")
    ExpressVendingMachines cha2(@Param("id") Integer id);
    @Select("select * from express_list where id=#{id}")
    ExpressList cha3(@Param("id") Integer id);
    @Select("select * from express_payment_records where id=#{id}")
    ExpressPaymentRecords cha4(@Param("id") Integer id);
    @Select("select * from express_account where type=2 and id=#{id}")
    ExpressAccount cha5(@Param("id") Integer id);
    @Update("update express_package set qujianma=#{p.qujianma} where id=#{p.id}")
    void chong(@Param("p") Package p);
    @Insert("insert into express_dispatch_message (deliveryid,content,create_date) values #{id},'重发送件码','送件码已经重发' ")
    void tian(@Param("id") Long id);

    @Select("select count(*) as num, sum(delivery_fee) - sum(discount_amount) as profit\n" +
            "from express_payment_records\n" +
            "where order_type = 1\n" +
            "  and DATE(over_time) = CURDATE()")
    Count deliveryCount();//今天派件数量和收入

    @Select("select count(*) as num, sum(delivery_fee) - sum(discount_amount) as profit\n" +
            "from express_payment_records\n" +
            "where order_type = 2\n" +
            "  and DATE(over_time) = CURDATE()")
    Count sendCount();//今天寄件数量和收入

    @Select("select count(*) num,DATE_FORMAT(over_time, '%Y-%m') month from express_payment_records\n" +
            "WHERE order_type = 1 GROUP BY DATE_FORMAT(over_time, '%Y-%m')\n" +
            "order by month")
    List<LineChart> findLineChartDelivery();//派件折线图数据

    @Select("select count(*) num,DATE_FORMAT(over_time, '%Y-%m') month from express_payment_records\n" +
            "WHERE order_type = 2 GROUP BY DATE_FORMAT(over_time, '%Y-%m')\n" +
            "order by month")
    List<LineChart> findLineChartSend();//寄件折线图数据

    @Insert("insert into express_dispatch_message (deliveryid,title,content) values (#{m.deliveryid},#{m.title},#{m.content})")
    void add(@Param("m") Message m);
}
